package com.hust.bridgecheck.repository;

import com.hust.bridgecheck.entity.Threshold;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ThresholdRepository extends JpaRepository<Threshold,Integer> {

    @Query(nativeQuery = true,value = "select t.id,t.bid,t.creat_time,t.first_threshold,t.second_threshold,t.sensorid,t.threshold_name,t.uid,s.cd_name,s.para_type_code,b.name from threshold t inner join sensor s on t.sensorid = s.para_id inner join bridge b on t.bid = b.id")
    List<Object> getAllDetail();

    @Query(nativeQuery = true,value = "select * from threshold where sensorid = ?1")
    Threshold getThresholdBySensorID(String sensorID);

    @Query(nativeQuery = true,value = "select t.id,t.bid,t.creat_time,t.first_threshold,t.second_threshold,t.sensorid,t.threshold_name,t.uid,s.cd_name,s.para_type_code,b.name from threshold t inner join sensor s on t.sensorid = s.para_id inner join bridge b on t.bid = b.id where t.threshold_name = ?1")
    List<Object> getThresholdByThresholdName(String SensorID);

    @Query(nativeQuery = true,value = "select t.id,t.bid,t.creat_time,t.first_threshold,t.second_threshold,t.sensorid,t.threshold_name,t.uid,s.cd_name,s.para_type_code,b.name from threshold t inner join sensor s on t.sensorid = s.para_id inner join bridge b on t.bid = b.id where t.bid = ?1")
    List<Object> getThresholdByBID(Integer BID);
}
